package com.jsz.peini.service.payment;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jsz.peini.bean.payment.PaymentInfo;
import com.jsz.peini.bean.user.UserAccount;
import com.jsz.peini.common.constants.Constants;
import com.jsz.peini.mapper.payment.PaymentInfoMapper;
import com.jsz.peini.mapper.user.UserAccountMapper;

@Service
public class PaymentInfoService {
	
	@Resource
	private PaymentInfoMapper paymentInfoMapper;
	
	@Resource
	private UserAccountMapper userAccountMapper;
	
	public void insert(PaymentInfo paymentInfo){
		int result = 0;
		UserAccount userAccount = new UserAccount();
		userAccount.setUserId(paymentInfo.getUserId());
		userAccount.setPayType(paymentInfo.getPayType());
		userAccount.setPayMoneyType(paymentInfo.getPayMoneyType());
		if(paymentInfo.getPayMoneyType().equals(Constants.PAY_GOLD)){//金币
			userAccount.setGold(paymentInfo.getPayMoney());
			result = userAccountMapper.updateGoldByUserId(userAccount);
		}else if(paymentInfo.getPayMoneyType().equals(Constants.PAY_SCORE)){//积分
			userAccount.setScore(paymentInfo.getPayMoney());
			result = userAccountMapper.updateScoreByUserId(userAccount);
		}else{//金钱
			
		}
		if(result>0){
			paymentInfoMapper.insert(paymentInfo);
		}
	}
	
}
